<template>
    <van-row>
        <div :id="chartid" style="width:100%;min-height:350px;padding 10px 0px" :style="chartStyle"></div>
    </van-row>
</template>

<script>
const echarts = require('echarts')
export default {
  name: 'AnalysisBarChart',
  props: ['chartid', 'title', 'chartStyle'],
  data () {
    return {
      echarts: null,
      options: null,
      chartData1: []
    }
  },
  mounted () {
    this.echarts = echarts.init(document.getElementById(this.chartid))
    this.options = {
      title: {
        text: this.title
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      grid: {
        containLabel: true
      },
      xAxis: {
        type: 'value',
        show: true
      },
      yAxis: {
        type: 'category',
        data: []
      },
      series: [
        {
          type: 'bar',
          label: {
            show: true
          },
          data: []
        }
      ]
    }
  },
  methods: {
    renderData (d) {
      console.log(d)
      this.chartData1 = d
      this.options.yAxis.data = []
      this.options.series[0].data = []
      if (this.chartData1.length > 0) {
        for (let i = 0; i < this.chartData1.length; i++) {
          this.options.yAxis.data[i] = this.chartData1[i].field
          this.options.series[0].data[i] = this.chartData1[i].count
        }
        console.log(this.options)
        this.echarts.setOption(this.options)
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>
